package com.cnjson.sensor.db.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
/**
 * 
 * @author lili
 *
 */
public class SetIdUtils {
    private Date now;
    private static int number = 0;
    private static final int MAX = 9999;

    private String setNumber() {
            String no;
            
            if (number == MAX) {
                    number = 0;
            } else {
                    number++;
            }

            if (number > 999) {
                    no = "";
            } else if (number > 99) {
                    no = "0";
            } else if (number > 9) {
                    no = "00";
            } else {
                    no = "000";
            }
            return no + String.valueOf(number);
    }

    public String setId() {
            now = new Date();
            String add = setNumber();
            SimpleDateFormat time = new SimpleDateFormat("yyyyMMddHHmmss");
            String id = add + time.format(now);
            System.out.println("id = " + id);
            return id;
    }
}
